package com.cjj.mvpsample.model.BeanBizImp;

import android.content.Context;
import android.content.SharedPreferences;

import com.cjj.mvpsample.model.Bean.User;
import com.cjj.mvpsample.model.IBeanBiz.IUserBiz;
import com.cjj.mvpsample.view.DefaultApplication;

/**
 * 用户业务逻辑
 * MVP中的M
 *
 * @Author：Created by cjj on 16/8/9.
 * @Blog：jianjunchen.net
 */
public class UserBizImp implements IUserBiz {
    private static final String USER = "user";
    private static final String SEX = "sex";
    private static final String USERNAME = "username";
    private static final String AGE = "age";

    @Override
    public void setUser() {
        SharedPreferences preferences = DefaultApplication.getInstance().getSharedPreferences(USER, Context.MODE_PRIVATE);
        preferences.edit()
                .putString(AGE, "100")
                .putString(SEX, "男")
                .putString(USERNAME, "MVP")
                .commit();
    }

    @Override
    public User getUser() {
        SharedPreferences preferences = DefaultApplication.getInstance().getSharedPreferences(USER, Context.MODE_PRIVATE);
                User user = new User();
        user.setAge(preferences.getString(AGE,""));
        user.setSex(preferences.getString(SEX,""));
        user.setUserName(preferences.getString(USERNAME,""));
        return user;
    }
}
